package com.punai.standard.controller;

import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.enums.BusinessType;
import com.punai.standard.domain.StaVersion;
import com.punai.standard.service.IStaVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 版本Controller
 * 
 * @author zxw
 * @date 2022-12-13
 */
@RestController
@RequestMapping("/sta/version")
public class StaVersionController extends BaseController
{
    @Autowired
    private IStaVersionService staVersionService;

    /**
     * 查询版本列表
     */
    @GetMapping("/list/{type}")
    public AjaxResult list(@PathVariable("type") String type)
    {
        List<StaVersion> list = staVersionService.getVersionList(type,getCompanyId());
        return AjaxResult.success(list);
    }


    /**
     * 查询版本列表
     */
    @GetMapping("/getNewestVersionsId/{type}")
    public AjaxResult getNewestVersionsId(@PathVariable("type") String type)
    {
        return AjaxResult.success(staVersionService.getNewestVersionsId(type,getCompanyId()));
    }

    // 第一次发布费用项
    @PreAuthorize("@ss.hasPermi('sta:version:publishCL')")
    @Log(title = "费用项-第一次发布", businessType = BusinessType.INSERT)
    @PutMapping("/publishOneCL")
    public AjaxResult subpkPublishOneCL(@RequestBody StaVersion staVersion)
    {
        return AjaxResult.success(staVersionService.newPublish(staVersion,getCompanyId()));
    }

    @PreAuthorize("@ss.hasPermi('sta:version:publishJX')")
    @Log(title = "费用项-第一次发布", businessType = BusinessType.INSERT)
    @PutMapping("/publishOneJX")
    public AjaxResult subpkPublishOneJX(@RequestBody StaVersion staVersion)
    {
        return AjaxResult.success(staVersionService.newPublish(staVersion,getCompanyId()));
    }

    // 同步费用项
    @PreAuthorize("@ss.hasPermi('sta:version:publish')")
    @Log(title = "费用项-同步", businessType = BusinessType.UPDATE)
    @PutMapping("/coverPublish")
    public AjaxResult coverSubpkPublish(@RequestBody StaVersion staVersion)
    {
        return AjaxResult.success(staVersionService.coverPublish(staVersion,getCompanyId()));
    }

    // 同步工序费用项
    @PreAuthorize("@ss.hasPermi('sta:version:publishCL')")
    @Log(title = "工序费用项-发布", businessType = BusinessType.INSERT)
    @PutMapping("/newPublishCL")
    public AjaxResult newSubpkPublishCL(@RequestBody StaVersion staVersion)
    {
        return AjaxResult.success(staVersionService.newPublish(staVersion,getCompanyId()));
    }

    // 同步工序费用项
    @PreAuthorize("@ss.hasPermi('sta:version:publishJX')")
    @Log(title = "工序费用项-发布", businessType = BusinessType.INSERT)
    @PutMapping("/newPublishJX")
    public AjaxResult newSubpkPublishJX(@RequestBody StaVersion staVersion)
    {
        return AjaxResult.success(staVersionService.newPublish(staVersion,getCompanyId()));
    }
}
